import 'package:amap_flutter/amap_flutter.dart';
import 'package:fl_extended/fl_extended.dart';
import 'package:flutter/material.dart';

class MapViewPage extends StatefulWidget {
  const MapViewPage({super.key});

  @override
  State<MapViewPage> createState() => _MapViewPageState();
}

class _MapViewPageState extends State<MapViewPage> {
  AMapController? controller;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('高德地图')),
      body: AMapView(
        options: const AMapOptions(
          mapType: MapType.standard,
          zoom: 15,
          maxZoom: 20,
          minZoom: 10,
          isTouchPoiEnable: false,
          showCompass: true,
          showMapText: true,
          showTraffic: false,
          showScale: false,
          showIndoorMap: false,
          showBuildings: false,
          showUserLocation: false,
          showUserLocationButton: false,
          // 阜宁县江苏水工入海水道2期工程1标段项目部
          latLng: LatLng(33.672318, 119.50346),
        ),
        onCreateController: (AMapController controller) {
          this.controller = controller;
          controller.setTrackingMode(
            isAndroid ? TrackingMode.followLocationRotate : TrackingMode.follow,
          );
          controller.android?.addListener(
            onMapLoaded: () {
              controller.addCustomTileLayer(
                "https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
                zIndex: 10,
              );
            },
          );
          controller.ios?.addListener();
        },
      ),
    );
  }

  @override
  void dispose() {
    controller?.dispose();
    super.dispose();
  }
}
